<?php

/** @var \Illuminate\Database\Eloquent\Factory $factory */

use App\Models\Admin;
use App\Models\Article;
use Spatie\Permission\Models\Role;
use App\User;
use Faker\Generator as Faker;
use Illuminate\Support\Str;

/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| This directory should contain each of the model factory definitions for
| your application. Factories provide a convenient way to generate new
| model instances for testing / seeding your application's database.
|
*/

$factory->define(User::class, function (Faker $faker) {
    return [
        'name' => $faker->name,
        'avatar' => env('DEFAULT_AVATAR'),
        'email' => $faker->unique()->safeEmail,
        'mobile' => mt_rand(13000000000,13900000000),
        'email_verified_at' => now(),
        'is_lock' => $faker->randomElement([-1,1]),
        'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
        'remember_token' => Str::random(10),
    ];
});

$factory->define(Admin::class, function (Faker $faker) {
    return [
        'name' => $faker->name,
        'email' => $faker->unique()->safeEmail,
        'email_verified_at' => now(),
        'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
        'remember_token' => Str::random(10),
    ];
});

$factory->define(Article::class, function (Faker $faker) {
    $user_ids = \App\User::pluck('id')->random();
    //$category_ids = \App\Category::pluck('id')->random();
    $title = $faker->sentence(mt_rand(3,10));
    return [
        'user_id'      => $user_ids,
        'category_id'  => 0,//$category_ids,
        'last_user_id' => $user_ids,
        'slug'     => str_slug($title),
        'title'    => $title,
        'content'  => $faker->paragraph,
        'page_image'       => $faker->imageUrl(),
        'meta_description' => $faker->sentence,
        'is_draft'         => false,
        'published_at'     => $faker->dateTimeBetween($startDate = '-2 months', $endDate = 'now')
    ];
});

$factory->define(Role::class, function (Faker $faker) {
    //$user_ids = \App\User::pluck('id')->random();
    //$category_ids = \App\Category::pluck('id')->random();
    $title = $faker->sentence(mt_rand(3,10));
    return [
        'name'    => $title,
        'guard_name' => $faker->randomElement(['admin','user']),
    ];
});

$factory->define(\Spatie\Permission\Models\Permission::class, function (Faker $faker) {
    //$user_ids = \App\User::pluck('id')->random();
    //$category_ids = \App\Category::pluck('id')->random();
    return [
        'name'    => $faker->name,
        'guard_name' => $faker->randomElement(['admin','user']),
        'display_name' => $faker->name,
    ];
});
